package com.example.demo.controller;

import com.example.demo.pojo.Evaluation;
import com.example.demo.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/evaluation")
public class EvaluationController {
    @Autowired
    private EvaluationService evaluationService;

    //评论列表查询
    @GetMapping("/findByUserid")
    public Object findByUserid(@RequestParam("userid") String userid) {
        HashMap<String, Object> map = new HashMap();
        List<Evaluation> list = evaluationService.findByUserid(userid);
        if (list.size() > 0) {
            map.put("code", 200);
            map.put("msg", "评论查询成功");
            map.put("data", list);
        } else {
            map.put("code", 300);
            map.put("msg", "暂无评论");
        }
        return map;
    }

    //添加评论
    @PostMapping("/addEvaluation")
    public Object addEvaluation(@RequestBody Evaluation evaluation) {
        HashMap<String, Object> map = new HashMap();
        int i = evaluationService.addEvaluation(evaluation);
        if (i > 0) {
            map.put("code", 200);
            map.put("msg", "评论提交成功");
        } else {
            map.put("code", 300);
            map.put("msg", "评论提交失败");
        }
        return map;
    }
}
